package com.h3bpm.web.msg.mobset.sms;

import com.h3bpm.web.msg.mobset.bean.DataObjectBean;
import com.h3bpm.web.msg.mobset.bean.msmResultBean;
import com.h3bpm.web.msg.mobset.factory.DataObjectFactory;
import com.h3bpm.web.msg.tempuri.MobsetApiSoap;
import com.h3bpm.web.msg.util.MD5;

import javax.xml.rpc.holders.LongHolder;
import javax.xml.rpc.holders.StringHolder;
import java.net.URL;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * ���Ų���*/
public class Sms_GetBalance {
	private static long corpID;      					//��ҵID
	private static String loginName;					//��¼�ʺ�
	private static String password;						//���룬MD5(CorpID+�ʺ�����+TimeStamp)
	private static	URL url;
	private static String timeStamp = "1105203910";			//ʱ�����MMDDHHMMSS������ʱ����),��0514094912
	private static StringHolder errMsg;					//������Ϣ�����ڷ��غ������ý������������
	private static LongHolder balance;					//�����ʺŵĿ��ö������

	public static msmResultBean getRecv(){
		
		Date now = new Date(); 
		SimpleDateFormat dateFormat = new SimpleDateFormat("MMddHHmmss");//���Է�����޸����ڸ�ʽ
		timeStamp = dateFormat.format(now); 
		System.out.println(timeStamp); 
		
		//���ʵ�������󼰳�ʼ������
		//MobsetApiSoap mobset = DataObjectFactory.getMobsetApi();
		errMsg = new StringHolder();
		balance = new LongHolder();
		msmResultBean msmBean = new msmResultBean();
		
		//��ȡ�ʺ���Ϣ
		DataObjectBean bean = DataObjectFactory.getInstance();
		corpID = new Long(bean.getCordId());
		loginName = bean.getUserName();
		password = bean.getPasswd();
		//���ʵ��������
	    try
	    {
	      url=new URL(bean.getServerIP());
		}
		catch (Exception e) {
					// TODO Auto-generated catch block
		   e.printStackTrace();
		}
		 MobsetApiSoap mobset = DataObjectFactory.getMobsetApi(url);
		
		//MD5�������
		MD5 md5 = new MD5();
		password = md5.getMD5ofStr(corpID+password+timeStamp);
		
		try {
			//���û�ȡ������ȡ�ʺŵĿ��ö������
			mobset.sms_GetBalance(corpID, loginName, password, timeStamp, balance, errMsg);
			msmBean.setErrMsg(errMsg);
			msmBean.setBalance(balance);
			
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return msmBean;
	}
}
